package com.andy.common.extend

import androidx.core.os.ConfigurationCompat
import com.andy.base.AppHelper
import java.text.SimpleDateFormat
import java.util.*


/**
 * 格式化毫秒级时间
 */
fun Long.formatMilliSecondTime(): String {
    if (this <= 0) {
        return ""
    }
    val currentLocale = ConfigurationCompat.getLocales(AppHelper.mContext.resources.configuration)[0] ?: return ""
    val timeCalendar = Calendar.getInstance(currentLocale)
    timeCalendar.timeInMillis = this
    val format = SimpleDateFormat("MM月dd日", Locale.CHINA)
    return format.format(this)
}

/**
 * 格式化毫秒级时间
 */
fun Long.formatTime(): String {
    if (this <= 0) {
        return ""
    }
    val currentLocale = ConfigurationCompat.getLocales(AppHelper.mContext.resources.configuration)[0] ?: return ""
    val timeCalendar = Calendar.getInstance(currentLocale)
    timeCalendar.timeInMillis = this
    val format = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)
    return format.format(this)
}